<template>
  <div class="app-container-custom">
    <el-descriptions class="margin-top" :column="4" size="small" border>
      <el-descriptions-item>
        <template slot="label">
          房屋名称
        </template>
        {{descForm.roomName}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          客户
        </template>
        {{ descForm.ownerVo?descForm.ownerVo.ownerName:''}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          使用面积
        </template>
        {{ descForm.roomArea}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          建筑面积
        </template>
        {{ descForm.buildArea}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          详细地址
        </template>
        {{ descForm.address}}
      </el-descriptions-item>
    </el-descriptions>
      <div style="margin-top: 10px;"/>

      <el-table
        ref="table"
        v-loading="loading"
        :data="roomNormList"
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="收费标准" align="center" prop="feeCondition.normNames"/>
        <el-table-column label="单价" align="center" prop="feeCondition.prices"/>
        <el-table-column label="月费用" align="center" prop="feeCondition.monthlyFee"/>
        <el-table-column label="交讫年月" align="center" prop="deliveryTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="缴费截止月" align="center" prop="paymentCycle">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.paymentCycle"
              type="month"
              value-format="yyyy-MM-dd"
              placeholder="选择月"
              :picker-options="{disabledDate:(time)=>{return disabledDate(time,scope.row.disabledDate)}}"
            >
            </el-date-picker>
          </template>
        </el-table-column>
      </el-table>

    <div class="dialog-footer" style="text-align: right;margin-top: 10px;">
      <el-button type="primary" @click="submitForm" :disabled="this.currentSelection.length < 1">生成费用</el-button>
    </div>
  </div>
</template>

<script>
import { listRoomNorm } from "@/api/payfee/roomNorm";
import { getRoom } from "@/api/property/room";
import { createRuleCost } from "@/api/payfee/tollCenter";

export default {
  name: "createCharge",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 房屋收费标准表格数据
      roomNormList: [],
      // 查询参数
      queryParams: {
        roomId:null,
        projectId:'01'
      },
      //当前选中节点
      currentSelection:[],
      descForm:{}
    };
  },
  created() {

  },
  methods: {
    disabledDate(time,paymentCycle) {
      let nexMothDay = this.getNextMonthDay(paymentCycle,-1);
      let date = new Date(nexMothDay);
      return time.getTime() <  date.getTime();
    },
    show(options){
      getRoom(node.id).then(res=>{
        this.descForm = res.data
      })
      this.queryParams.roomId = node.id
      this.getList()
    },
    /** 查询房屋收费标准列表 */
    getList() {
      this.loading = true;
      listRoomNorm(this.queryParams).then(response => {
        let roomNormList = response.rows;
        for(let i in roomNormList){
          let row = roomNormList[i]
          if(row.nextFinishChargetime){
            //row.paymentCycle = this.parseTime(this.getNextMonthDay(row.nextFinishChargetime,1),'{y}-{m}-{d}')
            row.paymentCycle = this.parseTime(row.nextFinishChargetime,'{y}-{m}-{d}')
          }else{
            row.paymentCycle = this.parseTime(row.beginChargeTime,'{y}-{m}-{d}')
          }
          row.disabledDate = row.paymentCycle
        }
        this.roomNormList = response.rows;
        this.$nextTick(() => {
          this.$refs.table.toggleAllSelection(); // 全选
        });
        this.loading = false;
      });
    },
    submitForm(){
      let form = {
        nodeId:this.currentNode.id,
        modelType:this.currentNode.modelType,
        roomNorms:this.currentSelection
      }
      createRuleCost(form).then(res=>{
        this.msgSuccess("房屋费用创建成功！");
        this.$emit("ok")
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.currentSelection = selection
    }
  }
};
</script>
